// @Title  channel_cache.go
// @Description  项目的所有channel
// @Author  IT搬运工
// @Update
package container

import "sync"

//设备通道列表
var devDataChannelMap = make(map[string]chan []byte)

var lock sync.RWMutex

//获取设备的通道
func GetDevChannel(channelId string) chan []byte {
	lock.RLock()
	defer lock.RUnlock()
	value, ok := devDataChannelMap[channelId]
	if ok {
		return value
	}
	return nil
}

//创建设备通道
func CreateDevChannel(channelId string) {
	lock.Lock()
	defer lock.Unlock()
	_, ok := devDataChannelMap[channelId]
	if !ok {
		chanName := make(chan []byte, 20)
		devDataChannelMap[channelId] = chanName
	}

}

//销毁设备通道
func DestroyDevChannel(channelId string) {
	lock.Lock()
	defer lock.Unlock()
	chanName, ok := devDataChannelMap[channelId]
	if ok {
		delete(devDataChannelMap, channelId)
		close(chanName)
	}
}
